<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title>管理员后台</title>
		<link rel="stylesheet" type="text/css" th:href="@{/css/cart.css}" />
		<link rel="stylesheet" type="text/css" th:href="@{/dist/css/bootstrap.min.css}">
		<link rel="stylesheet" type="text/css" th:href="@{/css/index.css}"/>
		<link rel="stylesheet" type="text/css" th:href="@{/css/animate.css}"/>
		<link rel="stylesheet" th:href="@{/layui/css/layui.css}">

	</head>

	<body>
    <!--导航部分  begin-->
    <div th:replace="admin/common/header :: nav"></div>
    <!--导航部分 end-->

		<!--购物车 begin-->
		<!--外层div-->

<!--		<div id="allUsersData"></div>-->
	<div class="container">
		<!--左边-->
		<div class="col-md-8 col-sm-12" style="width:100%">
			<!--左边-->
			<ol class="breadcrumb">
				<li>
					<a href="#" class="text-success"><span class="glyphicon glyphicon-heart"></span>&nbsp;&nbsp;用户信息管理</a>
				</li>
			</ol>

			<!--购物车表格 begin-->
			<div class="table-responsive" id="imgDiv">
				<table class="table table-hover table-striped" style="vertical-align:middle;">
					<thead>
					<!--						<tr>
                                                <td colspan="8">
                                                    <label class="text-primary">显示条数:</label>
                                                    <select id="cartSzie" class="form-control" style="display: inline" onchange="displaySize(this)">
                                                        <option value="2">2</option>
                                                        <option value="4">4</option>
                                                        <option value="6" selected>6</option>
                                                        <option value="8">8</option>
                                                    </select>
                                                </td>
                                            </tr>-->
					<tr class="text-success success">
						<th style="width: 30px;">
<!--							<input type="checkbox" id="selectAll" onclick="selectAll(this)">-->
							<!--								<input type="checkbox" id="testId" onclick="selectAll(this)">-->
						</th>
						<th id="sequence">序号</th>
						<th>用户名</th>
						<th>密码</th>
						<th>邮箱</th>
						<th>电话</th>
						<th>学校</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody id="tby" th:each="user,iter:${userList}">
					<tr>
						<td style="width: 30px;">
<!--							<input type="checkbox" name="cks"  th:value="${user.id}" >-->
							<!--								<input type="checkbox" name="cks" onclick="cks(this)" name="testName" value="${item.id}">-->
						</td>
						<td th:text="${user.id}">1001</td>
						<td th:text="${user.username}">腾讯传</td>
						<td th:text="${user.password}">作者</td>
						<td th:text="${user.email}">黑龙江科学技术出版社</td>
						<td th:text="${user.phone}">分类</td>
						<!--							<span th:switch="${book.cate}">
                                                        <td th:case="'SELECTTED'">精选图书</td>
                                                        <td th:case="'RECOMMEND'">精选图书</td>
                                                        <td th:case="'BARGAGIN'">精选图书</td>
                                                    </span>-->
						<td th:text="${user.school}">原价</td>


						<td th:if="${user.state == 1}">
							<a th:onclick="forbidUser([[${user.id}]])"  class="btn btn-success">封号</a>
						</td>
						<td th:if="${user.state == 2}">
							<a th:onclick="unforbidUser([[${user.id}]])"  class="btn btn-danger">解封</a>
						</td>

					</tr>
					</tbody>
                    <tr style="background-color: white;">
                        <td>
                            <a href="#" data-toggle="modal" data-target="#addUserModal" class="btn btn-info">
                                添加用户＋
                            </a>
<!--                            <a th:href="@{/admin/toAddUser}" class="btn btn-info">添加用户＋</a>-->
                        </td>
                        <!--							<td><button class="btn btn-danger" data-toggle="modal" data-target="#myModal" th:onclick="deleteBooks()">删除商品一</button></td>-->
                        <td colspan="4"></td>
                        <!--							<td>
                                        <a href="confirm_order.html" class="btn btn-warning">结算商品</a>
                                      </td>-->
                    </tr>
					<tfoot>
					<tr>
						<td colspan="5"></td>
						<td class="text-success">总数量:</td>
						<td class="text-success" th:text="${userList.size()+'人'}"></td>
					</tr>
					<tr style="background-color: white;">

<!--						<td><button class="btn btn-success" data-toggle="modal" data-target="#myModal" th:onclick="deleteUsers()">批量封号</button></td>-->
						<td colspan="4"></td>

					</tr>
					</tfoot>
				</table>
			</div>
			<!--购物车 end-->

		</div>

        <!-- 新增用户模态框 -->
        <div class="modal fade" id="addUserModal" tabindex="-1" role="dialog" aria-labelledby="notifyInfoModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <!-- 新增用户表单 -->
                    <div class="modal-header">
                        <h5 class="modal-title"  style="text-align: center;">添加用户</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form class="form" method="post" action="/book/admin/addUser" accept-charset="UTF-8">
                            <div class="form-group">
                                <label for="username">用户名：</label>
                                <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名" required>
                            </div>
                            <div class="form-group">
                                <label for="password">密码：</label>
                                <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码" required>
                            </div>
                            <div class="form-group">
                                <label for="email">邮箱：</label>
                                <input type="email" class="form-control" id="email" name="email" placeholder="请输入邮箱" required>
                            </div>
                            <div class="form-group">
                                <label for="phone">电话：</label>
                                <input type="tel" class="form-control" id="phone" name="phone" placeholder="请输入电话">
                            </div>
                            <div class="form-group">
                                <label for="school">学校：</label>
                                <input type="text" class="form-control" id="school" name="school" placeholder="请输入学校">
                            </div>
                            <button type="submit" class="btn btn-primary btn-block">提交</button>
                        </form>
                    </div>
                </div>
            </div>

    </div>

		<!--分页begin-->

		<!--分页end-->
	</div>
		<div class="container">
			<!--首页底部信息 begin-->
			<div th:replace="common/footer :: footer"></div>
		</div>
		<!--end-->

		<!--引入js文件-->
		<script src="js/details.js" th:src="@{/js/details.js}" type="text/javascript" charset="utf-8"></script>
		<script src="js/cart.js" th:src="@{/js/cart.js}" type="text/javascript" charset="utf-8"></script>
		<script src="dist/js/jquery.min.js" th:src="@{/dist/js/jquery.min.js}"></script>
		<script src="js/carousel.js" th:src="@{/js/carousel.js}" type="text/javascript" charset="utf-8"></script>
		<script src="dist/js/bootstrap.min.js" th:src="@{/dist/js/bootstrap.min.js}"></script>
		<script src="js/wow.js" th:src="@{/js/wow.js}"></script>
		<script th:src="@{/layui/layui.js}"></script>
		<script th:inline="javascript">
			//获取应用路径
			var contextPath = [[${#request.getContextPath()}]];
			var pages = [[${pages}]];
			var admin = [[${session.admin}]]
		</script>
		<script type="text/javascript">
			if(!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
				new WOW().init();
			};

		</script>

	<style type="text/css">
		td {text-align: center}
		th {text-align: center}
	</style>
	</body>
	<script>

		//批量封号
		function deleteUsers(){
			//存储购物记录的id
			var ids = '';
			var thirdModel = document.getElementById("third_del");
			//判断是否选择了商品
			var count = 0;
			//获取所有的checkbox
			var cks = document.getElementsByName("cks");
			//遍历
			for(var i = 0; i < cks.length; i++) {
				if(cks[i].checked) {
					count++;
					ids += cks[i].value + ",";
					// bookIds.add(cks[i].value);
				}
			}
			// var s = new Array();
			// for(var x of bookIds){
			// 	console.log(x)
			// }

			if (ids==''){
				layer.msg('请勾选账号！');
				return;
			}
			layer.confirm('确定封禁？', {
				icon:3,
				btn: ['确定', '取消']
			}, function(index, layero){
				//按钮【按钮一】的回调
				$.ajax({
					url:contextPath + "/admin/deleteUsers",
					data:{"ids":ids},
					type:"post",
					success:function (data) {
						if (data=="success"){
							location.href = contextPath + "/admin/toAllUsers";

						}
						else layer.msg("封号失败")

					}
				})
			}, function(index){
				return ;
			});
		//封号
		}

		function forbidUser(userId) {
			layer.confirm('确定封号？', {
				icon:3,
				btn: ['确定', '取消']
			}, function(index, layero){
				//按钮【按钮一】的回调
				layer.prompt({
					formType: 2,
					value: '',
					title: '请输入封禁原因',
					area: ['200px', '20px'] //自定义文本域宽高
				}, function(value, index, elem){
					// alert(value); //得到value
					$.ajax({
						url:contextPath + "/admin/forbidUser",
						data:{"userId":userId,"forbidReason":value},
						type:"post",
						success:function (data) {
							if (data=="success"){
								location.href = contextPath + "/admin/toAllUsers";
							}
							else layer.msg("封号失败")

						}
					})
					// layer.close(index);
				});

			}, function(index){
				return ;
			});
		}
		//解封
		function unforbidUser(userId) {
			layer.confirm('确定解封？', {
				icon:3,
				btn: ['确定', '取消']
			}, function(index, layero){
				//按钮【按钮一】的回调
				$.ajax({
					url:contextPath + "/admin/unforbidUser",
					data:{"userId":userId},
					type:"post",
					success:function (data) {
						if (data=="success"){
							location.href = contextPath + "/admin/toAllUsers";
						}
						else layer.msg("解封失败")

					}
				})
			}, function(index){
				return ;
			});
		}

		//根据用户名搜索
		function searchUsername() {
			var inputUsername = $("#inputUsername").val();
			if (inputUsername != ''){
				window.location.href = contextPath + "/admin/searchUser?inputUsername=" + inputUsername;
			}else alert('请输入用户名')
		}

		$(function () {
			if (admin == null || admin == undefined || admin == 'undefined') {
				location.href = contextPath + "/book/index";
			}
		})
	</script>

</html>